#include "Gameover.h"
#include "GameData.h"
#include "GameMenu.h"
CGameover::CGameover()
{
	curIndex = 0;
}

CGameover::~CGameover()
{
}

bool CGameover::init()
{
	if (!Scene::init()){
		return false;
	}

	
	auto visibleSize = Director::getInstance()->getVisibleSize();
	auto origin = Director::getInstance()->getVisibleOrigin();

	char picName[32] = {};
	for (int i = 0; i < 4; i++){
		sprintf_s(picName, "juqing0%d.png", i + 1);
		Sprite* pic = Sprite::createWithSpriteFrameName(picName);
		this->addChild(pic);
		pic->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2));
		pic->setOpacity(0);
		m_vecPic.push_back(pic);
	}
	m_vecPic[0]->setOpacity(255);
	
	
	EventListenerTouchOneByOne* pListener = EventListenerTouchOneByOne::create();
	pListener->onTouchBegan = CC_CALLBACK_2(CGameover::onTouchBegin, this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(pListener, this);
	return true;
}

bool CGameover::onTouchBegin(Touch*, Event*)
{
	if (curIndex == 3){
		CGameData::getInstance()->setRoleId(1002);
		Director::getInstance()->replaceScene(CGameMenu::create());
		return false;
	}
	++curIndex;
	FadeIn* fadeIn = FadeIn::create(1);
	m_vecPic[curIndex]->runAction(fadeIn);
	return true;
	
}


